package br.com.hs.nfe.common.importacao;

import br.com.hs.nfe.common.exception.HSCommonException;
import br.com.hs.nfe.common.util.IOHelper;
import br.com.hs.nfe.common.to.NotaFiscalTO;
import br.com.hs.nfe.common.util.DocumentConverter;
import br.com.hs.nfe.common.util.DocumentHelper;
import br.inf.portalfiscal.nfe.NFeDocument;

/**
 * Classe responsável pela importação dos dados da NF-e.
 * @author Ranlive Hrysyk
 */
public class ImportacaoBusiness {

    private static final String NFE_PROCESSADA = "";
    private static final String NFE_NAO_AUTORIZADA = "";

    public static NotaFiscalTO createNotaFiscal(String path) {
        try {
            String xml = readFile(path);
            NFeDocument doc = DocumentHelper.createNFeDocument(xml);
            NotaFiscalTO notaFiscalTO = DocumentConverter.createNotaFiscalTO(doc);
            return notaFiscalTO;
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
            return null;
        }
    }

    private static String readFile(String path) throws HSCommonException {
        return IOHelper.readFile(path);
    }
}
